﻿@using ZR.CodeGenerator
@using ZR.Model.System.Generate
@using Infrastructure.Extensions;
@* @model ZR.CodeGenerator.Model.GenerateDto; *@
@{
    var genTable = Model.GenTable;
    var subTableOptions = Model.SubTableOptions;
    var options = Model.GenOptions;
    var replaceDto = Model.ReplaceDto;
    bool showCustomInput = Model.GenTable.Columns.Any((Func<GenTableColumn, bool>)(f => f.HtmlType.Equals(GenConstants.HTML_CUSTOM_INPUT, StringComparison.OrdinalIgnoreCase)));
    var dictHtml = new string[] { GenConstants.HTML_CHECKBOX, GenConstants.HTML_RADIO, GenConstants.HTML_SELECT, GenConstants.HTML_SELECT_MULTI };
    var dicts = new List<GenTableColumn>();
    dicts.AddRange(Model.GenTable.Columns.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    if (Model.GenTable.SubTable != null && Model.GenTable.SubTableName.IsNotEmpty())
    {
        dicts.AddRange(Model.GenTable?.SubTable?.Columns?.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    }
}
@foreach(var column in genTable.Columns)
{
    var labelName = "";
    var labelDisabled = "";
    var columnName = column.CsharpFieldFl;
    var value = "item.dictValue";
    if(column.ColumnComment != "")
    {
        labelName = column.ColumnComment;
    }
    else
    {
        labelName = column.CsharpFieldFl;
    }
    if(column.IsPk == true)
    {
        labelDisabled = ":disabled=true";
    }
    if(column.CsharpType == "int" || column.CsharpType == "long")
    {
        value = "parseInt(item.dictValue)";
    }

    if (CodeGeneratorTool.CheckInputDtoNoField(column.CsharpField))
    {

    }
    else if (column.IsInsert == false && column.IsEdit == false)
    {
        continue;
    }
    else if (CodeGeneratorTool.CheckTree(genTable, column.CsharpField))
    {
        <el-col :lg="24">
            <el-form-item label="@(labelName)" prop="@(columnName)">
                <treeselect v-model="form.@(columnName)" :options="dataList" :normalizer="normalizer" :show-count="true" placeholder="选择@(labelName)" />
            </el-form-item>
        </el-col>
    }
    else if (column.IsPk || column.IsIncrement)
    {
        <el-col :lg="12">
        <el-form-item label="@(labelName)" prop="@(columnName)">
        @if (column.IsIncrement == false)
        {
            <el-input-number v-model.number="form.@(columnName)" controls-position="right" placeholder="请输入@(labelName)" :disabled="title=='修改数据'"/>
        }
        else
        {
            @:<span v-html="form.@(columnName)"/>
        }
        </el-form-item>
        </el-col>
    }
    else
    {
        if (column.HtmlType == "text")
        {
            <el-col :lg="12">
                <el-form-item label="@(labelName)">{{form.@(columnName)}}</el-form-item>
            </el-col>
        }
        else if (column.HtmlType == "inputNumber")
        {
            <el-col :lg="12">
                <el-form-item label="@(labelName)" prop="@(columnName)">
                  <el-input-number v-model.number="form.@(columnName)" controls-position="right" placeholder="请输入@(labelName)" @(labelDisabled)/>
                </el-form-item>
            </el-col>
        }
        else if(column.HtmlType == "datetime")
        {
                  <el-col :lg="12">
                    <el-form-item label="@(labelName)" prop="@(columnName)">
                      <el-date-picker v-model="form.@(columnName)" type="datetime" placeholder="选择日期时间"></el-date-picker>
                    </el-form-item>
                  </el-col>
        }
        else if(column.HtmlType == "imageUpload")
        {
                  <el-col :lg="24">
                    <el-form-item label="@(labelName)" prop="@(columnName)">
                       <UploadImage v-model="form.@(columnName)" column="@(columnName)" @@input="handleUploadSuccess" />
                    </el-form-item>
                  </el-col>
        }
        else if(column.HtmlType == "fileUpload")
        {
          <el-col :lg="24">
            <el-form-item label="@(labelName)" prop="@(columnName)">
              <UploadFile v-model="form.@(columnName)" column="@(columnName)" @@input="handleUploadSuccess" />
            </el-form-item>
          </el-col>
        }
        else if(column.HtmlType == "radio")
        {
          <el-col :lg="12">
            <el-form-item label="@(labelName)" prop="@(columnName)">
              <el-radio-group v-model="form.@(columnName)">
                <el-radio v-for="item in @(column.DictType != ""?column.DictType:$"{column.CsharpFieldFl}Options")" :key="item.dictValue" :label="@(value)">{{item.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        }
        else if(column.HtmlType == "textarea")
        {
          <el-col :lg="24">
            <el-form-item label="@(labelName)" prop="@(columnName)">
              <el-input type="textarea" v-model="form.@(columnName)" placeholder="请输入@(labelName)"/>
            </el-form-item>
          </el-col>
        }
        else if(column.HtmlType == "editor")
        {
          <el-col :lg="24">
            <el-form-item label="@(labelName)" prop="@(columnName)">
              <editor v-model="form.@(columnName)" :min-height="200" />
            </el-form-item>
          </el-col>
        }
        else if(column.HtmlType == "select")
        {
          <el-col :lg="12">
            <el-form-item label="@(labelName)" prop="@(columnName)">
              <el-select v-model="form.@(columnName)" placeholder="请选择@(labelName)">
                <el-option v-for="item in @(column.DictType != ""?column.DictType:$"{column.CsharpFieldFl}Options")" :key="item.dictValue" :label="item.dictLabel" :value="@(value)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        }
        else if(column.HtmlType == "checkbox")
        {
          <el-col :lg="24">
            <el-form-item label="@(labelName)" prop="@(columnName)">
              <el-checkbox-group v-model="form.@(columnName)Checked">
                <el-checkbox v-for="item in @(column.DictType != ""?"options.@(column.DictType}":$"options.{column.CsharpFieldFl}Options")" :key="item.dictValue" :label="item.dictValue">{{item.dictLabel}}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        }
        else
        {
          <el-col :lg="12">
            <el-form-item label="@(labelName)" prop="@(columnName)">
              <el-input v-model="form.@(columnName)" placeholder="请输入@(labelName)" @(labelDisabled)/>
            </el-form-item>
          </el-col>
        }
    }
}